//logs.js
const util = require('../../utils/util.js')
var network = require("../../api/api.js")
Page({
  data: {
    logs: [],
      initial: false
  },
  onLoad: function () {
    this.setData({
      logs: (wx.getStorageSync('logs') || []).map(log => {
        return util.formatTime(new Date(log))
      })
    })
  },
    onShow: function () {
      this.setData({initial: false})
        this.setData({initial: true})
    },
  loginx() {
    wx.login({
      success: function (res) {
        if (res.code) {
          //发起网络请求
          var params = new Object()
          params.business_param = {
            code: res.code
          }
          network.POST({
            params: params,
            url: "wechat_access_token",
            success: function (res) {
              var params = new Object()
              params.business_param = {
                login_type: 3,
                // openid: 'o52D9439wsO9Cpp2TiA8RedRbinE'
                openid: (res.result[0] || {}).openid
                // openid: (res.result[0] || {}).openid || '2134567891234567891234514898'
                // openid: res.openid || '2134567891234567891234514898'
                // openid: res.openid || '1234567891234567891234501810'
              }
              network.POST({
                params: params,
                url: "customer_register",
                success: function (userLogin) {
                  const userLoginData = userLogin.result[0] || {}

                  wx.setStorageSync('user_login', userLogin.result[0] || {})
                  let isRead = wx.getStorageSync('isRead') || 0;
                  if (isRead == 0) {
                    wx.navigateTo({
                      url: '../learning/learning'
                    })
                  } else {
                    util.authJudge(userLoginData)
                  }
                }
              })
              //拿到解密后的数据，进行代码逻辑

            },
            fail: function () {
              //失败后的逻辑

            },
          })
        } else {
          console.log('登录失败！' + res.errMsg)
        }
      }
    });
  }
})